#!/bin/bash

#
# Flow stability for dynamic community detection https://arxiv.org/abs/2101.06131v2
#
# Copyright (C) 2021 Alexandre Bovet <alexandre.bovet@maths.ox.ac.uk>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


# This script runs the computation of the clustering
# for the case of the APS dataset


NAME="3650"
DIRECTION=$1

TIMESTAMP=$(date +%s)


JNAME="${NAME}_${TIMESTAMP}_${DIRECTION}"

NCPU=1
NPROC_FILES=4
NPROC_CLUST=4

# numpy/scipy number of threads
export OPENBLAS_NUM_THREADS=2
export OMP_NUM_THREADS=2

# to use int64 for MKL indexing. To allow more than 2**31 -1 elements
export MKL_INTERFACE_LAYER=ILP64

NETFILENAME="aps_monthly_lcc_net.pickle"

RUNDIR="$HOME/rundir"

DATADIRBASE="$HOME/datadir"

mkdir -p $DATADIRBASE

LAPINTERTRANSDIR="$DATADIRBASE/lapl_intertransmat"

INTEGDIR="$DATADIRBASE/integralgrid_complenet_forclust"

CLUSTSDIRI="$DATADIRBASE/clustersI_complenet_forward"

mkdir -p $LAPINTERTRANSDIR
mkdir -p $CLUSTSDIRI
mkdir -p $INTEGDIR


CLUSTNUMREPEAT=24

NUMVARINFSAMPLES=200

NETNAME="aps_monthly"


# compute clustering of integral
python3 -u $RUNDIR/run_sparse_clustering.py \
        --datadir $INTEGDIR \
        --savedir $CLUSTSDIRI \
        --nproc_files $NPROC_FILES \
        --nproc_clustering $NPROC_CLUST \
        --num_repeat $CLUSTNUMREPEAT \
        --use_autocov_int \
        --net_name $NETNAME \
        --num_varinf_samples $NUMVARINFSAMPLES \
        --verbose 1 \
        --separate_comps \
        --init_p1 \
        --direction $DIRECTION \
        --save_clustering_before_nvarinf \
        --n_meta_iter_max 100 \
        --n_sub_iter_max 1000 \
        --print_num_loops \
        --integral_rtol 1e-9 \
        > output_${JNAME}_${SLURM_JOB_ID}_clust.txt 2> error_${JNAME}_${SLURM_JOB_ID}_clust.txt

# end
